from django.contrib import admin

# Register your models here.
from django.contrib import admin
from .models import *

@admin.register(FoodCategory)
class FoodCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'description']
    search_fields = ['name']

@admin.register(FoodItem)
class FoodItemAdmin(admin.ModelAdmin):
    list_display = ['name', 'category', 'created_at']
    list_filter = ['category']
    search_fields = ['name', 'tags']

@admin.register(DailyFoodRecord)
class DailyFoodRecordAdmin(admin.ModelAdmin):
    list_display = ['user', 'date', 'breakfast', 'lunch', 'dinner']
    list_filter = ['date', 'user']
    date_hierarchy = 'date'

@admin.register(UserPreference)
class UserPreferenceAdmin(admin.ModelAdmin):
    list_display = ['user', 'dietary_restrictions']
    filter_horizontal = ['preferred_categories', 'disliked_foods']


@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    list_display = ['name', 'color', 'created_by', 'created_at', 'get_food_count']
    list_filter = ['created_at', 'created_by']
    search_fields = ['name', 'description']
    readonly_fields = ['created_at']

    def get_food_count(self, obj):
        return obj.get_food_count()

    get_food_count.short_description = '关联食物数'


@admin.register(Caipu)
class CaipuAdmin(admin.ModelAdmin):
    pass